<template>
  <div>
    <SearchForm :onSearch="onSearch" :onReset="onReset" />
    <div class="chart-wrapper">
      <TablePlus
        :columns="columns"
        :data="sugarList"
        :pagination="pagination"
        :loading="loading"
        @on-change="onPageChange" />
    </div>
  </div>
</template>

<script>
import SearchForm from "./searchForm";
import TablePlus from "@/components/tablePlus";
import api from "@/api/commonApi";
import Utils from '@/utils';
const pagination = {
  pageNo: 1,
  pageSize: 10,
  count: 1
};
export default {
  components: {
    SearchForm,
    TablePlus
  },
  data() {
    return {
      sugarList: [],
      columns: [
        { title: '排序', type: 'index', width: 60, align: 'center' },
        { title: '日期', key: 'updateTime', render(h, params) {
          return params.row.updateTime.slice(0 ,10);
        }},
        { title: '医生', key: 'doctorName' },
        { title: '健康建议', key: 'suggest' }
      ],
      pagination: { ...pagination },
      dataValues: {},
      loading: false
    }
  },
  mounted() {
    this.patientwSuggestPage();
  },
  methods: {
    onSearch(values) {
      this.dataValues = values;
      this.patientwSuggestPage();
    },
    onReset() {
      this.dataValues = {};
      this.pagination = { ...pagination };
      this.patientwSuggestPage();
    },
    onPageChange(pagination) {
      this.pagination = pagination;
      this.patientwSuggestPage();
    },
    patientwSuggestPage() {
      const reqBody = {
        pageNo: this.pagination.pageNo,
        pageSize: this.pagination.pageSize,
        params: {
          memberId: this.$route.params.id
        }
      };
      this.dataValues.fromTime && (reqBody.params.createTime_GOE = Utils.getNowDateBySpecialFormat(this.dataValues.fromTime));
      this.dataValues.endTime && (reqBody.params.createTime_LT = Utils.getNowDateBySpecialFormat(this.dataValues.endTime));
      this.loading = true;
      console.log(JSON.stringify(reqBody));
      this.$axios.post(api.patientwSuggestPage, reqBody).then(res => {
        if (res.data.code === 1) {
          this.sugarList = res.data.object.list;
          this.pagination.count = res.data.object.count;
          this.loading = false;
        } else {
          this.$Message.info(res.data.message);
        }
      }).catch(() => {
      });
    },
  },
  watch: {
    'pagination.pageSize'(n, o) {
      this.patientwSuggestPage();
    }
  }
}
</script>

<style scoped lang="less">
.chart-wrapper {
  height: 400px;
}
</style>